{include file="public/nheader"}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }
</style>
<style type="text/css">
    .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
        height: auto;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    {if $quanx == 1}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input value="{:input('get.created')}" name="created" lay-datetime=""
                                data-format="yyyy-MM-dd" data-type="date" class="layui-input" type="text"
                                placeholder="线索获取日期" />
                        </div>
                    </div>
                    {/if}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input value="{:input('get.createds')}" name="createds" lay-datetime=""
                                data-format="yyyy-MM-dd" data-type="date" class="layui-input" type="text"
                                placeholder="推送到本平台日期" />
                        </div>
                    </div>
                    {if $quanx == 1}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="isexcel" lay-verify="">
                                <option value="">线索类型</option>
                                <option value="1" {if !empty(input('get.isexcel')) &&
                                    input('get.isexcel')==1}selected{/if}>飞鱼推送</option>
                                <option value="2" {if !empty(input('get.isexcel')) &&
                                    input('get.isexcel')==2}selected{/if}>EXCEL导入</option>
                                <option value="3" {if !empty(input('get.isexcel')) &&
                                    input('get.isexcel')==3}selected{/if}>系统库线索</option>
                            </select>
                        </div>
                    </div>
                    {/if}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="repeats" lay-verify="">
                                <option value="">是否重复</option>
                                <option value="1" {if !empty(input('get.repeats')) &&
                                    input('get.repeats')==1}selected{/if}>不重复数据</option>
                                <option value="2" {if !empty(input('get.repeats')) &&
                                    input('get.repeats')==2}selected{/if}>重复数据</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="allocation" lay-verify="">
                                <option value="">是否已分配</option>
                                <option value="1" {if !empty(input('get.allocation')) &&
                                    input('get.allocation')==1}selected{/if}>未分配</option>
                                <option value="2" {if !empty(input('get.payment')) &&
                                    input('get.allocation')==2}selected{/if}>已分配</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="youxiao" lay-verify="">
                                <option value="">是否有效</option>
                                <option value="1" {if !empty(input('get.youxiao')) &&
                                    input('get.youxiao')==1}selected{/if}>有效</option>
                                <option value="2" {if !empty(input('get.youxiao')) &&
                                    input('get.youxiao')==2}selected{/if}>无效</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="type" lay-verify="">
                                <option value="">筛选品牌</option>
                                {foreach $pinpai as $pp}
                                <option value="{$pp.type}" {if !empty(input('get.type')) &&
                                    input('get.type')==$pp.type}selected{/if}>{$pp.pinpai}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    {if $quanx == 1}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="adv_id" class="layui-input" type="text" placeholder="广告ID|视频ID|广告主ID|计划ID搜索" />
                        </div>
                    </div>
                    {/if}
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="address" class="layui-input" type="text" placeholder="地区模糊搜索(如湖南长沙,请按长沙搜索)" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="手机号|微信|姓名搜索" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/lista/lista_status?status=isdel">批量删除
                        </button>
                        <button class="layui-btn icon-btn" lay-batch="lay-tableList"
                            data-url="/lista/lista_status2?status=repeats">批量标重
                        </button>
                        <button class="layui-btn icon-btn layui-btn-warm" id="excels">EXCEL导入线索
                        </button>
                        <a οnclick="event.cancelBubble=true" target="_blank"
                            href="http://adall.gxfacai888.cn/excel2025/gssdxl1.xlsx">(上传示例下载)</a>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" style="color:#FF5722" data-url="/lista/lista_status?id={{d.id}}&status=isdel" data-reload="self" data-confirm="" lay-ajax="">删除</a>
    {{#  if(d.repeats ==1){ }}
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" style="color:#1890ff" data-url="/lista/lista_status2?id={{d.id}}&status=repeats" data-reload="self" data-confirm="" lay-ajax="">标重</a>
    {{#  } }}
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form', 'upload'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;      // 表格
        var form = layui.form;
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#excels' //绑定元素
            , accept: 'file'
            , url: '/lista/import_gsdxl' //上传接口
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(); //上传loading
            }
            , done: function (res) {
                layer.closeAll('loading'); //关闭loading
                //如果上传失败
                if (res.status == 0) {
                    var str = '';
                    $.each(res.data, function (i, obj) {
                        console.log(i, obj);
                        str += '<div>' + obj + '</div>';
                    });
                    layer.open({
                        type: 0,
                        content: str,
                        yes: function () {
                            location.reload();
                        }
                    });
                    return false;
                } else {
                    layer.msg(res.mag, { icon: 2, time: 1000 });
                    return false;
                }
            }
            , error: function () {
                layer.closeAll('loading'); //关闭loading
                layer.msg('请求失败请重试', { icon: 2, time: 1000 });
                return false;

            }
        });
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {

                // 获取用户id
                var pageThat = layui.$(this);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                post.field.status = 3;
                layui.$.post("{:url('orders/order_status')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                    }
                    else {
                        layer.error(res.msg);
                    }
                }, 'json');
                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , where: {
                //created: "{:input('created',date('Y-m-d'))}",
            }
            , toolbar: 'true'
            // , defaultToolbar: ["filter","exports","print"]
            , defaultToolbar: [{
                title: '导出excel' //标题
                , layEvent: 'LAYTABLE_EXPORT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-export' //图标类名
            }, {
                title: '打印页面' //标题
                , layEvent: 'LAYTABLE_PRINT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-print' //图标类名
            }, {
                title: '筛选数据' //标题
                , layEvent: 'LAYTABLE_COLS' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-cols' //图标类名
            }]
            , even: true
            , loading: true
            , limits: [10, 20, 40, 60, 80, 100, 150, 200, 300, 100000]
            , limit: 10
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'pinpai', width: 100, align: 'center', title: '品牌' },
                //{ field: 'id', align: 'center', sort: true, title: 'ID' },
                {
                    field: 'laiyuans', width: 180, align: 'center', title: '来源', templet: function (d) {
                        return d.fplaiyuan_name + '';
                    }
                },
                { field: 'name', width: 100, align: 'center', title: '姓名' },
                { field: 'phone', width: 140, align: 'center', title: '手机号' },
                { field: 'othertel', width: 120, align: 'center', title: '其他联系方式' },
                { field: 'address', width: 120, align: 'center', title: '地址' },
                {
                    field: 'created', width: 250, align: 'center', title: '日期', templet: function (d) {
                        var html = '';
                        if (d.show == 1) {
                            if (d.name) {
                                html += '留资时间:' + d.created + '<br/>';
                            }
                            if (d.name) {
                                html += '推送时间:' + d.createds + '<br/>';
                            }
                        } else {
                            html += d.createds;
                        }
                        return html;
                    }
                },
                { field: 'pingtai', width: 120, align: 'center', title: '线索渠道' },
                {
                    field: 'source', width: 100, align: 'center', title: '线索类型', templet: function (d) {
                        if (d.source == 0) {
                            return '表单提交';
                        }
                        return '在线留言';
                    }
                },
                {
                    field: 'adv_id', width: 250, align: 'center', title: '相关ID', templet: function (d) {
                        var html = '';
                        if (d.adv_id) {
                            html += '广告主ID:' + d.adv_id + '<br/>';
                        }
                        if (d.promotion_id) {
                            html += '广告ID:' + d.promotion_id + '<br/>';
                        }
                        if (d.videoid) {
                            html += '视频ID:' + d.videoid + '<br/>';
                        }
                        if (d.isexcel !== 1) {
                            html = '';
                        }
                        return html;
                    }
                },
                {
                    field: 'youxiao', width: 70, align: 'center', title: '有效', templet: function (d) {
                        if (d.youxiao == 1) {
                            return '<a class="layui-table-text"  style="color:#1890ff">有效</a>';
                        }
                        if (d.youxiao == 2) {
                            return '<a class="layui-table-text" style="color:#FF5722">无效</a>';
                        }
                        return '未知';
                    }
                },
                //{
                //    field: 'yxtext', width: 120, align: 'center', title: '无效备注', templet: function (d) {
                //        if (d.yxtext) {
                //            return d.yxtext;
                //        }
                //       return '无';
                //   }
                //},
                {
                    field: 'yxtags', width: 100, align: 'center', title: '标签'
                },
                {
                    field: 'repeats', width: 70, align: 'center', title: '重复', templet: function (d) {
                        if (d.repeats == 1) {
                            return '<a class="layui-table-text" style="color:#1890ff">否</a>';
                        }
                        return '<a class="layui-table-text" style="color:#FF5722">是</a>';
                    }
                },
                {
                    field: 'allocation', width: 70, align: 'center', title: '分配', templet: function (d) {
                        if (d.allocation == 1) {
                            return '<a class="layui-table-text" style="color:#FF5722">否</a>';
                        }
                        return '<a class="layui-table-text" style="color:#1890ff">是</a>';
                    }
                },
                //{ field: 'remark', width: 100, align: 'center', title: '用户备注' },
                { field: 'name', toolbar: '#tableBar', width: 120, align: 'center', title: '操作' },
            ]],
            done: function (res, curr, count) { // 表格渲染完成之后的回调
                if (res.count == null) { // 无数据时直接返回了
                    return;
                }
                // 这里可以换成你的逻辑，也可以对其它列做处理
                var testAValue = res.isshow;
                if (testAValue != 1) {
                    $("[data-field='laiyuans']").css('display', 'none');
                    $("[data-field='pingtai']").css('display', 'none');
                    $("[data-field='adv_id']").css('display', 'none');
                    $("[data-field='yxtext']").css('display', 'none');
                }
                // 重新渲染
                table.render('select');
            }
        })
    })
</script>